package org.wings27.utils;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;

/**
 * Project Name: answerIt
 * Date Created: 2013/11/21 17:38
 *
 * @author wings
 */
public class FileReader {
    private BufferedReader reader;
    private String filePath;

    public FileReader() throws IOException {
        this("");
    }

    public FileReader(String filePath) throws IOException {
        this(filePath, Charset.defaultCharset());
    }

    public FileReader(String filePath,Charset charset) throws IOException {
        this.filePath = filePath;
        InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(this.filePath),charset);
        this.reader = new BufferedReader(inputStreamReader);
    }

    public String readBlock() throws IOException {
        String result = "";
        String line = reader.readLine();
        while (line != null && !line.trim().equals("")) {
            result += line + System.lineSeparator();
            line = reader.readLine();
        }
        return result;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }
}
